package com.ruoyi.web.controller.repair;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.repairQuery.domain.RepairQuery;
import com.ruoyi.repairQuery.service.IRepairQueryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 维修记录查询Controller
 * 
 * @author ruoyi
 * @date 2023-05-31
 */
@RestController
@RequestMapping("/repair/repairQuery")
public class RepairQueryController extends BaseController
{
    @Autowired
    private IRepairQueryService repairQueryService;

    /**
     * 查询维修记录查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RepairQuery repairQuery)
    {
        startPage();
        RepairQuery repairQueryVO = new RepairQuery();
        List<RepairQuery> list = repairQueryService.selectRepairQueryList(repairQuery);
        if(getDataTableSumJudge(list)){
            repairQueryVO = repairQueryService.selectRepairQuerySum(repairQuery);
            repairQueryVO.setProjectId("合计");
            list.add(repairQueryVO);
        }
        return getDataTable(list);
    }

    /**
     * 导出维修记录查询列表
     */
    @Log(title = "维修记录查询", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RepairQuery repairQuery)
    {
        RepairQuery repairQueryVO = new RepairQuery();
        List<RepairQuery> list = repairQueryService.selectRepairQueryList(repairQuery);
        if(getDataTableSumJudge(list)){
            repairQueryVO = repairQueryService.selectRepairQuerySum(repairQueryVO);
            repairQueryVO.setProjectId("合计");
            list.add(repairQueryVO);
        }
        ExcelUtil<RepairQuery> util = new ExcelUtil<RepairQuery>(RepairQuery.class);
        util.exportExcel(response, list, "维修记录查询数据");
    }

    /**
     * 获取维修记录查询详细信息
     */
    @GetMapping(value = "/{checkId}")
    public AjaxResult getInfo(@PathVariable("checkId") Long checkId)
    {
        return AjaxResult.success(repairQueryService.selectRepairQueryByCheckId(checkId));
    }

}
